<template>
  <div>
    <el-button @click='$router.push("/goods-add")' type="success">添加商品</el-button>
    <el-table :data="goodsList" style="width: 100%">
      <el-table-column type="index"></el-table-column>
      <el-table-column prop="goods_name" label="商品名称" width="180"></el-table-column>
      <el-table-column prop="goods_price" label="商品价值" width="180"></el-table-column>
      <el-table-column prop="goods_number" label="商品数量"></el-table-column>
      <el-table-column prop="add_time" label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.add_time | dataFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" plain type="primary" icon="el-icon-edit"></el-button>
          <el-button size="mini" plain type="danger" icon="el-icon-delete"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
/* eslint-disable-next-line */
import moment from 'moment';

export default {
  data () {
    return {
      goodsList: []
    }
  },
  created () {
    this.loadGoodsList()
  },
  methods: {
    /**
     * 加载商品数据
     */
    async loadGoodsList () {
      let res = await this.$axios.get('goods', {
        params: {
          pagenum: 1,
          pagesize: 5
        }
      })
      // console.log(res)
      this.goodsList = res.data.data.goods
    }
  },
  filters: {
    // 时间过滤器
    dataFilter (date) {
      return moment(date).format('YYYY-MM-DD hh:mm:ss')
    }
  }
}
</script>

<style>
</style>
